        <template  #reference>
  <div style="margin-top: 20px" class="classification">
    <div style="margin-top: 20px; margin-bottom: 20px; padding-left: 40px">
      <el-button
        type="success"
        @click="dialogFormVisible = true"
        style="margin-right: 30px"
        ><el-icon><Plus /></el-icon>增加</el-button
      >

      <el-popover :visible="visible" placement="top" :width="160">
        <p>你确定要删除吗？</p>
        <div style="text-align: right; margin: 0">
          <el-button size="small" text @click="visible = false">删除</el-button>
          <el-button size="small" type="primary" @click="visible = false"
            >取消</el-button
          >
        </div>
        <template #reference>
          <el-button type="danger" @click="visible =true">
            <el-icon><Delete /></el-icon>批量删除</el-button
          >
        </template>
      </el-popover>
    </div>
  </div>

  <!-- Form -->
  <el-dialog v-model="dialogFormVisible" title="添加商品">
    <el-form :model="form" label-width="120px">
      <el-form-item label="商品名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="请输入商品名称">
        <el-select v-model="form.region" placeholder="商品类型">
          <el-option label="电器" value="shanghai" />
          <el-option label="衣物" value="beijing" />
        </el-select>
      </el-form-item>
      <el-form-item label="添加时间">
        <el-col :span="11">
          <el-date-picker
            v-model="form.date1"
            type="date"
            placeholder="Pick a date"
            style="width: 100%"
          />
        </el-col>
        <el-col :span="2" class="text-center">
          <span class="text-gray-500">-</span>
        </el-col>
        <el-col :span="11">
          <el-time-picker
            v-model="form.date2"
            placeholder="Pick a time"
            style="width: 100%"
          />
        </el-col>
      </el-form-item>
      <el-form-item label="发布">
        <el-switch v-model="form.delivery" />
      </el-form-item>
      <el-form-item label="标签">
        <el-checkbox-group v-model="form.type">
          <el-checkbox label="便宜" name="type" />
          <el-checkbox label="质量" name="type" />
          <el-checkbox label="美观" name="type" />
          <el-checkbox label="快乐" name="type" />
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="资源">
        <el-radio-group v-model="form.resource">
          <el-radio label="Sponsor" />
          <el-radio label="Venue" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="详细信息">
        <el-input v-model="form.desc" type="textarea" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>

  <el-table
    ref="multipleTableRef"
    :data="tableData"
    style="width: 100%"
    height="750px"
    @selection-change="handleSelectionChange"
  >
    <el-table-column type="selection" width="55" />
    <el-table-column property="shopname" label="商品名称" width="220" />
    <el-table-column property="url" label="跳转链接" width="220" />
    <el-table-column property="number" label="排序值" width="220" />
    <el-table-column
      property="bianhao"
      label="商品编号"
      show-overflow-tooltip
    />
    <el-table-column property="time" label="添加时间" width="220" />

    <el-table-column fixed="right" label="操作" width="120">
      <template #default #reference>
        <el-button
          link
          type="primary"
          size="small"
          @click="dialogFormVisible = true"
          >修改</el-button
        >
        <el-button link type="primary" size="small" text @click="open"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
        
        <script lang="ts" setup>
import { reactive, ref } from "vue";
import { ElTable } from "element-plus";
import { ElMessage, ElMessageBox } from "element-plus";
const dialogFormVisible = ref(false);
const visible = ref(false);

//删除商品
const open = () => {
  ElMessageBox.confirm("你确定要删除这个商品吗？", "商品信息", {
    confirmButtonText: "删除",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      ElMessage({
        type: "success",
        message: "删除成功",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "删除失败",
      });
    });
};

//获取后台信息
const form = reactive({
  name: "",
  region: "",
  date1: "",
  date2: "",
  delivery: false,
  type: [],
  resource: "",
  desc: "",
});
interface User {
  date: string;
  name: string;
  address: string;
}
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
const multipleSelection = ref<User[]>([]);
const toggleSelection = (rows?: User[]) => {
  if (rows) {
    rows.forEach((row) => {
      // TODO: improvement typing when refactor table
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      //@ts-expect-error
      multipleTableRef.value!.toggleRowSelection(row, directive);
    });
  } else {
    multipleTableRef.value!.clearSelection();
  }
};
const handleSelectionChange = (val: User[]) => {
  multipleSelection.value = val;
};
const tableData = ref<User[]>([]);
fetch("http://rap2api.taobao.org/app/mock/308829/xin/ping")
  .then((reponse) => {
    // console.log('res:',reponse)
    return reponse.json();
  })
  .then((data) => {
    console.log(data.xinping);
    tableData.value = data.xinping;
  });
</script>
        <style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>